1

Is there a way to associate the return value of an inputText with more than one attrribute?

Like this (it's a sample, value1 and value2 tag attributes does not exist in the syntax):

<h:inputText id="matricula" 
             value1="#{alunoController.aluno.matricula}" 
             value2="#{alunoHasCursoController.alunoHasCurso.matricula}">
</h:inputText>

Thanks in advance!

SRy
  • 2,901
  • 8
  • 36
  • 57
Johann Gomes
  • 3,813
  • 5
  • 23
  • 25
  • `value` is a predefined attribute in the framework. You can't define your own attributes as `value1,value2...` and did you try to keep this format in your page and check? – SRy Mar 07 '13 at 23:57
  • This is a code smell. I don't believe the capability exists and for good reason. It's sloppy design. – kolossus Mar 08 '13 at 02:11

3 Answers3

0

Maybe just pass inputText value directly to bean method (described here) and in this method you can associate it to multiple variables/fields.

Community
  • 1
  • 1
Iwo Kucharski
  • 3,735
  • 3
  • 50
  • 66
  • I will explain deeply my problem> I have two models: Student and Student_has_Course Both models have the attribute registration. I need to make both models have this attribute registration set with the same value, received by the inputText. Or there is a way of inside one model, access another to catch the value without reinstantiate it? – Johann Gomes Mar 08 '13 at 00:40
  • @JohannGomes, please explain the concrete problem in the actual question – kolossus Mar 08 '13 at 02:08
0

Use an f:valueChangeListener to cause the changes to be sent to the second bean.

user207421
  • 305,947
  • 44
  • 307
  • 483
0
<h:inputText
    value1="#{alunoController.aluno.matricula}" 
    value2="#{alunoHasCursoController.alunoHasCurso.matricula}">

Why do you need copies? This is bad design. Java is object oriented and allows you to reference a single object instance by multiple references.

You just need to ensure that #{alunoHasCursoController.alunoHasCurso} references exactly the very same #{alunoController.aluno} instance.

E.g.

public class AlunoHasCursoController {

    @ManagedProperty("#{alunoController.aluno}")
    private Aluno alunoHasCurso;

    // ...
}

So that you can get away with

<h:inputText
    value="#{alunoController.aluno.matricula}">

Or the other way round, depending on the context and functional requirement.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555