Determine UIComponent that call valueBinding

Hi All,

This is my code:

<h:form>

<h:inputText value="#{myBean.inputValue}" id="test1"></h:inputText>

<h:inputText value="#{myBean.inputValue}"id="test2"></h:inputText>

<h:commandButton

value="submit"

action="#{myBean.action}"

/>

</h:form>

Cause of the same target binding (Bean.inputValue) I need to catch (in MyBean class) which of the two components is calling the binding.

Thanks a lot.

[505 byte] By [dokkka] at [2007-11-26 16:33:04]
# 1

Ummm.. could you please rephrase the questions? Are you asking which of the 2 will be bound to the inputValue parameter? They both will? and if you enter 2 different texts into each of the text boxes and submit the form Im pretty sure the "test2" will be called after the setting of the first therefore both inputs will eventually read what you put into "test2" .....? why would you do this?

jbayugaa at 2007-7-8 22:57:43 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2

Sorry for my confusing explanation jbayuga...

I try to be cleaner:

I have a page with some inputText(s) that bind to the same bean and to the same property (inputValue in the example).

In the bean i have to understand which is the inputText calling the binding, so i can do something like this:

public class MyBean {

private String inputValue;

// getter for the binding property

public String getInputValue()

{

if(INPUTTEXT_CALLING.id == test1)

{

return "something";

}

else if(INPUTTEXT_CALLING.id == test2)

{

return "something else";

}

}

}

Note: INPUTTEXT_CALLING is just the Object I would to capture to understand which inputText is calling the binding.

I hope it's clear now... If not I can try again!

dokkka at 2007-7-8 22:57:43 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3

This isn't possible. But why do you want to do this? This is a .. weird .. approach. What if the both fields are filled in? Can you please provide a practical example where such a construction would be a big benefit?

Anyway, if you want to use only one bean property for multiple input fields, it might be a better practice to use a Map property.

JSF<h:inputText value="#{myBean.input.test1}" />

<h:inputText value="#{myBean.input.test2}" />

<h:commandButton value="submit" action="#{myBean.action}" />

MyBeanprivate Map input = new HashMap(); // + getter + setter

public void action() {

if (input.get("test1") != null) {

// do something1

}

if (input.get("test2") != null) {

// do something2

}

}

BalusCa at 2007-7-8 22:57:43 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 4

I'm going to explain how the application is structured now.

The front-end layer is composed by jsp(s) with relative bean(s), for example:

- Customer.jsp -> Customer.java

- Carrier.jsp -> Carrier.java

etc...

Every UIComponent has method binding.

The back-end layer is composed by Value Objects that represent the business entities

- CustomerVO.java

- CarrierVO.java

etc...

Actually the way to map the Value Object(s) fields to a gui, is by using a class called GuiManager.java. This works this way:

- I pass the bean (Customer.java) to GuiManager

- the GuiManager instatiates the relative VO (CustomerVO.java)

- it takes the bean, cycles through its accessor methods and sets or gets the inputText by getting the value from/to the relative VO. To do that is used naming convention, so the property "name" of the VO has its corresponding inputText called "input_Customer_name" in the bean (Customer.java).

I believe this is not a good way (am I right?).

So I would the change it by delete method binding and by using value binding.

dokka at 2007-7-8 22:57:43 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...