Dynamic Rendering and Common Paramenters

View: New views
8 Messages — Rating Filter:   Alert me  

Dynamic Rendering and Common Paramenters

by Gonzalo Aguilar Delgado-4 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hello Again!

I have a form that I build dynamically based on a render parameter
value. I'm using
http://cwiki.apache.org/WICKET/forms-with-dynamic-elements.html


I use the constructor:

/**
         * Constructor
         */
        public ViewModePage()
        {

        ...

                // Get render parameter
                String value =
((PortletRequestContext)RequestContext.get()).getPortletRequest().getParameter("crmportal:userId");
        ...
                // Check for a valid answer from this customer
                if(value!=null && value.length()>0)
                {
                        log.debug("Value length: " + value.length());
                        User user = userDAOBean.find(UuidUserType.fromString(value));

                        if(user!=null)
                        {
                                answer = getLastAnswer(1,user);
                                if(answer!=null)
                                {
                                        buildForm(answer);
                                        surveySubmitButton.setEnabled(true);
                                }
                        }
                }
        ...
       
        }
------------------------------------------------------------------------------------

buildForm(answer); gets the form build based on the user answer

The problem as you can figure out. It works as I do nothing with the
form... But when I submit the form the constructer gets not
called anymore. So no matter what's the value it will get not updated to
the new one.

The GREAT book "wicket in action" explained this issue well. You have to
use dynamic models:


---------------------------- CODE ----------------------------------
    In chapter 4, we’ll discuss the differences between static models
and dynamic mod-
els (the issue at hand) in greater depth. For now, we’ll solve the
problem by providing
the label with a model that calculates its value every time it’s
requested:

add(new Label("total", new Model() {
     @Override
    public Object getObject() {
         NumberFormat nf = NumberFormat.getCurrencyInstance();
         return nf.format(getCart().getTotal());
     }
}));

-------------------WICKET IN ACTION ----------------------------


But as I have to build the form I do not have a dynamic model on page.
So how do I make the form gets updated each time
the page it's rendered without disturbing Wicket normal behaviour?

Do I explain myself?

Thank you all in advance.


















Re: Dynamic Rendering and Common Paramenters

by Pedro H. O. dos Santos :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

> But when I submit the form the constructer gets not called anymore.
this is an expected behavior, an component instance is held on pagemap
between requests.

> But as I have to build the form I do not have a dynamic model on page.
Can't you manage an instance of an dynamic model on your component,
independent of your form build logic? You can. Figure out the best way to
your component. You can simple keep this model on an instance variable for
example.

On Tue, Nov 3, 2009 at 7:22 AM, Gonzalo Aguilar Delgado <
gaguilar@...> wrote:

> Hello Again!
>
> I have a form that I build dynamically based on a render parameter
> value. I'm using
> http://cwiki.apache.org/WICKET/forms-with-dynamic-elements.html
>
>
> I use the constructor:
>
> /**
>         * Constructor
>         */
>        public ViewModePage()
>        {
>
>        ...
>
>                // Get render parameter
>                String value =
>
> ((PortletRequestContext)RequestContext.get()).getPortletRequest().getParameter("crmportal:userId");
>        ...
>                // Check for a valid answer from this customer
>                if(value!=null && value.length()>0)
>                {
>                        log.debug("Value length: " + value.length());
>                        User user =
> userDAOBean.find(UuidUserType.fromString(value));
>
>                        if(user!=null)
>                        {
>                                answer = getLastAnswer(1,user);
>                                if(answer!=null)
>                                {
>                                        buildForm(answer);
>                                        surveySubmitButton.setEnabled(true);
>                                }
>                        }
>                }
>        ...
>
>        }
>
> ------------------------------------------------------------------------------------
>
> buildForm(answer); gets the form build based on the user answer
>
> The problem as you can figure out. It works as I do nothing with the
> form... But when I submit the form the constructer gets not
> called anymore. So no matter what's the value it will get not updated to
> the new one.
>
> The GREAT book "wicket in action" explained this issue well. You have to
> use dynamic models:
>
>
> ---------------------------- CODE ----------------------------------
>    In chapter 4, we’ll discuss the differences between static models
> and dynamic mod-
> els (the issue at hand) in greater depth. For now, we’ll solve the
> problem by providing
> the label with a model that calculates its value every time it’s
> requested:
>
> add(new Label("total", new Model() {
>     @Override
>    public Object getObject() {
>         NumberFormat nf = NumberFormat.getCurrencyInstance();
>         return nf.format(getCart().getTotal());
>     }
> }));
>
> -------------------WICKET IN ACTION ----------------------------
>
>
> But as I have to build the form I do not have a dynamic model on page.
> So how do I make the form gets updated each time
> the page it's rendered without disturbing Wicket normal behaviour?
>
> Do I explain myself?
>
> Thank you all in advance.
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>


--
Pedro Henrique Oliveira dos Santos

Re: Dynamic Rendering and Common Paramenters

by Gonzalo Aguilar Delgado-4 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Let me see if I understand what you say.

I should build the form inside a component instead the page. And I
should keep a reference
to the dynamic model inside this component.

This makes sense for me but I find one problem. Where do I read the
renderer parameter?

Because this code gets executed in the main page.

---------------------------- CODE ----------------------------
 // Get render parameter
                String value =
((PortletRequestContext)RequestContext.get()).getPortletRequest().getParameter("crmportal:userId");

--------------------------------------------------------------


I can do it in submit but then I should be able to communicate it to the
new component and
make it render again.

Is there a common way to do this in wicket?


Thank you



El mar, 03-11-2009 a las 08:00 -0200, Pedro Santos escribió:

> > But when I submit the form the constructer gets not called anymore.
> this is an expected behavior, an component instance is held on pagemap
> between requests.
>
> > But as I have to build the form I do not have a dynamic model on page.
> Can't you manage an instance of an dynamic model on your component,
> independent of your form build logic? You can. Figure out the best way to
> your component. You can simple keep this model on an instance variable for
> example.
>
> On Tue, Nov 3, 2009 at 7:22 AM, Gonzalo Aguilar Delgado <
> gaguilar@...> wrote:
>
> > Hello Again!
> >
> > I have a form that I build dynamically based on a render parameter
> > value. I'm using
> > http://cwiki.apache.org/WICKET/forms-with-dynamic-elements.html
> >
> >
> > I use the constructor:
> >
> > /**
> >         * Constructor
> >         */
> >        public ViewModePage()
> >        {
> >
> >        ...
> >
> >                // Get render parameter
> >                String value =
> >
> > ((PortletRequestContext)RequestContext.get()).getPortletRequest().getParameter("crmportal:userId");
> >        ...
> >                // Check for a valid answer from this customer
> >                if(value!=null && value.length()>0)
> >                {
> >                        log.debug("Value length: " + value.length());
> >                        User user =
> > userDAOBean.find(UuidUserType.fromString(value));
> >
> >                        if(user!=null)
> >                        {
> >                                answer = getLastAnswer(1,user);
> >                                if(answer!=null)
> >                                {
> >                                        buildForm(answer);
> >                                        surveySubmitButton.setEnabled(true);
> >                                }
> >                        }
> >                }
> >        ...
> >
> >        }
> >
> > ------------------------------------------------------------------------------------
> >
> > buildForm(answer); gets the form build based on the user answer
> >
> > The problem as you can figure out. It works as I do nothing with the
> > form... But when I submit the form the constructer gets not
> > called anymore. So no matter what's the value it will get not updated to
> > the new one.
> >
> > The GREAT book "wicket in action" explained this issue well. You have to
> > use dynamic models:
> >
> >
> > ---------------------------- CODE ----------------------------------
> >    In chapter 4, we’ll discuss the differences between static models
> > and dynamic mod-
> > els (the issue at hand) in greater depth. For now, we’ll solve the
> > problem by providing
> > the label with a model that calculates its value every time it’s
> > requested:
> >
> > add(new Label("total", new Model() {
> >     @Override
> >    public Object getObject() {
> >         NumberFormat nf = NumberFormat.getCurrencyInstance();
> >         return nf.format(getCart().getTotal());
> >     }
> > }));
> >
> > -------------------WICKET IN ACTION ----------------------------
> >
> >
> > But as I have to build the form I do not have a dynamic model on page.
> > So how do I make the form gets updated each time
> > the page it's rendered without disturbing Wicket normal behaviour?
> >
> > Do I explain myself?
> >
> > Thank you all in advance.
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
>
>

Re: Dynamic Rendering and Common Paramenters

by Pedro H. O. dos Santos :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

 >I should build the form inside a component instead the page. And I
>should keep a reference
>to the dynamic model inside this component.
Not what I try to mean.

your report:
>But as I have to build the form I do not have a dynamic model on page.
You can have your model, and you can have your component build logic.

you report:

>So no matter what's the value it will get not updated to
>the new one.
so i think you are working on diferent answer instances
can you send some buildForm(answer) lines?

On Tue, Nov 3, 2009 at 9:22 AM, Gonzalo Aguilar Delgado <
gaguilar@...> wrote:

> Let me see if I understand what you say.
>
> I should build the form inside a component instead the page. And I
> should keep a reference
> to the dynamic model inside this component.
>
> This makes sense for me but I find one problem. Where do I read the
> renderer parameter?
>
> Because this code gets executed in the main page.
>
> ---------------------------- CODE ----------------------------
>  // Get render parameter
>                String value =
>
> ((PortletRequestContext)RequestContext.get()).getPortletRequest().getParameter("crmportal:userId");
>
> --------------------------------------------------------------
>
>
> I can do it in submit but then I should be able to communicate it to the
> new component and
> make it render again.
>
> Is there a common way to do this in wicket?
>
>
> Thank you
>
>
>
> El mar, 03-11-2009 a las 08:00 -0200, Pedro Santos escribió:
>
> > > But when I submit the form the constructer gets not called anymore.
> > this is an expected behavior, an component instance is held on pagemap
> > between requests.
> >
> > > But as I have to build the form I do not have a dynamic model on page.
> > Can't you manage an instance of an dynamic model on your component,
> > independent of your form build logic? You can. Figure out the best way to
> > your component. You can simple keep this model on an instance variable
> for
> > example.
> >
> > On Tue, Nov 3, 2009 at 7:22 AM, Gonzalo Aguilar Delgado <
> > gaguilar@...> wrote:
> >
> > > Hello Again!
> > >
> > > I have a form that I build dynamically based on a render parameter
> > > value. I'm using
> > > http://cwiki.apache.org/WICKET/forms-with-dynamic-elements.html
> > >
> > >
> > > I use the constructor:
> > >
> > > /**
> > >         * Constructor
> > >         */
> > >        public ViewModePage()
> > >        {
> > >
> > >        ...
> > >
> > >                // Get render parameter
> > >                String value =
> > >
> > >
> ((PortletRequestContext)RequestContext.get()).getPortletRequest().getParameter("crmportal:userId");
> > >        ...
> > >                // Check for a valid answer from this customer
> > >                if(value!=null && value.length()>0)
> > >                {
> > >                        log.debug("Value length: " + value.length());
> > >                        User user =
> > > userDAOBean.find(UuidUserType.fromString(value));
> > >
> > >                        if(user!=null)
> > >                        {
> > >                                answer = getLastAnswer(1,user);
> > >                                if(answer!=null)
> > >                                {
> > >                                        buildForm(answer);
> > >
>  surveySubmitButton.setEnabled(true);
> > >                                }
> > >                        }
> > >                }
> > >        ...
> > >
> > >        }
> > >
> > >
> ------------------------------------------------------------------------------------
> > >
> > > buildForm(answer); gets the form build based on the user answer
> > >
> > > The problem as you can figure out. It works as I do nothing with the
> > > form... But when I submit the form the constructer gets not
> > > called anymore. So no matter what's the value it will get not updated
> to
> > > the new one.
> > >
> > > The GREAT book "wicket in action" explained this issue well. You have
> to
> > > use dynamic models:
> > >
> > >
> > > ---------------------------- CODE ----------------------------------
> > >    In chapter 4, we’ll discuss the differences between static models
> > > and dynamic mod-
> > > els (the issue at hand) in greater depth. For now, we’ll solve the
> > > problem by providing
> > > the label with a model that calculates its value every time it’s
> > > requested:
> > >
> > > add(new Label("total", new Model() {
> > >     @Override
> > >    public Object getObject() {
> > >         NumberFormat nf = NumberFormat.getCurrencyInstance();
> > >         return nf.format(getCart().getTotal());
> > >     }
> > > }));
> > >
> > > -------------------WICKET IN ACTION ----------------------------
> > >
> > >
> > > But as I have to build the form I do not have a dynamic model on page.
> > > So how do I make the form gets updated each time
> > > the page it's rendered without disturbing Wicket normal behaviour?
> > >
> > > Do I explain myself?
> > >
> > > Thank you all in advance.
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> >
> >
>



--
Pedro Henrique Oliveira dos Santos

Re: Dynamic Rendering and Common Paramenters

by Gonzalo Aguilar Delgado-4 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message




> >I should build the form inside a component instead the page. And I
> >should keep a reference
> >to the dynamic model inside this component.
> Not what I try to mean.


So what's the way?



>
> your report:
> >But as I have to build the form I do not have a dynamic model on page.
> You can have your model, and you can have your component build logic.


mmmm


>
> you report:
>
> >So no matter what's the value it will get not updated to
> >the new one.
> so i think you are working on diferent answer instances
> can you send some buildForm(answer) lines?


Yes but's somewhat large, anyway answer has got from the code I sent
earlier. But it got not
updated because this code goes in the constructor that never gets
called.

Here goes the code:


        public void buildForm(SurveyAnswer answer)
        {

                List<SurveyQuestion> listQuestions = getQuestionList(1); // FIXIT: How
do we get this questionaire?

                if(listQuestions!=null && listQuestions.size()>0)
                {

                        int category = -1;
                        QuestionCategoryComponent categoryComponent = null;

                        /*
                         * We add category containers to the component array and
                         * questions to the category containers.
                         *
                         */
                        for(Iterator<SurveyQuestion> iter = listQuestions.iterator();
iter.hasNext();)
                        {
                                SurveyQuestion question = iter.next();

                                // Check if we should start a new category
                                if(category !=
question.getSurveyQuestionCategory().getIdSurveyQuestionCategory())
                                {
                                        log.debug("Category: " +
question.getSurveyQuestionCategory().getQuestionCategoryDescription());
                                        categoryComponent = new
QuestionCategoryComponent("surveyComponent",
question.getSurveyQuestionCategory().getQuestionCategoryDescription());
                                        components.add(categoryComponent);
                                        category =
question.getSurveyQuestionCategory().getIdSurveyQuestionCategory();
                                }

                                if(categoryComponent!=null)
                                {
                                        SurveyQuestionResponse response = null;
                                        if(answer!=null)
                                        {
                                                response = surveyAnswerFactory.getResponse(question, answer);
                                                if(response.getIdSurveyQuestionResponse()==null)
                                                {
                                                        log.info("Creating a new answer for this question");

                                                        surveyQuestionResponseDAO.save(response);

                                                }
                                        }

                                        // Each question component holds question and answer
                                        try {

categoryComponent.add(QuestionComponentFactory.getComponent(question,
response));
                                        } catch (ComponentTypeException e) {
                                                try {
                                                        warn("Response for question: " +
question.getSurveyQuestionDescription() + " has incorrect response!");

categoryComponent.add(QuestionComponentFactory.getComponent(question));
                                                } catch (ComponentTypeException e1) {
                                                        log.error("Cannot create component");
                                                }
                                        }
                                }


                        }

                }
        }


>

Re: Dynamic Rendering and Common Paramenters

by Pedro H. O. dos Santos :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi Gonzalo, I thought that with buildForm implementation I will see how you
create your form component. But seams that it is created on the line:
QuestionComponentFactory.getComponent(question,response)

Instead of ask you for more code, I will try to explain myself:

>So no matter what's the value it will get not updated to the new one.
Any build component logic will stop you from create an form with an dynamic
model on it. I thing you are updating an object instance that isn't the one
on your form model.
on lines:
                        response = surveyAnswerFactory.getResponse(question,
answer);
and then:


categoryComponent.add(QuestionComponentFactory.getComponent(question,
                                response));
be sure of to work on the same response instance that is on your form model.

On Tue, Nov 3, 2009 at 1:38 PM, Gonzalo Aguilar Delgado <
gaguilar@...> wrote:

>
>
>
> > >I should build the form inside a component instead the page. And I
> > >should keep a reference
> > >to the dynamic model inside this component.
> > Not what I try to mean.
>
>
> So what's the way?
>
>
>
> >
> > your report:
> > >But as I have to build the form I do not have a dynamic model on page.
> > You can have your model, and you can have your component build logic.
>
>
> mmmm
>
>
> >
> > you report:
> >
> > >So no matter what's the value it will get not updated to
> > >the new one.
> > so i think you are working on diferent answer instances
> > can you send some buildForm(answer) lines?
>
>
> Yes but's somewhat large, anyway answer has got from the code I sent
> earlier. But it got not
> updated because this code goes in the constructor that never gets
> called.
>
> Here goes the code:
>
>
>        public void buildForm(SurveyAnswer answer)
>        {
>
>                List<SurveyQuestion> listQuestions = getQuestionList(1); //
> FIXIT: How
> do we get this questionaire?
>
>                if(listQuestions!=null && listQuestions.size()>0)
>                {
>
>                        int category = -1;
>                        QuestionCategoryComponent categoryComponent = null;
>
>                        /*
>                         * We add category containers to the component array
> and
>                         * questions to the category containers.
>                         *
>                         */
>                        for(Iterator<SurveyQuestion> iter =
> listQuestions.iterator();
> iter.hasNext();)
>                        {
>                                SurveyQuestion question = iter.next();
>
>                                // Check if we should start a new category
>                                if(category !=
> question.getSurveyQuestionCategory().getIdSurveyQuestionCategory())
>                                {
>                                        log.debug("Category: " +
> question.getSurveyQuestionCategory().getQuestionCategoryDescription());
>                                        categoryComponent = new
> QuestionCategoryComponent("surveyComponent",
> question.getSurveyQuestionCategory().getQuestionCategoryDescription());
>                                        components.add(categoryComponent);
>                                        category =
> question.getSurveyQuestionCategory().getIdSurveyQuestionCategory();
>                                }
>
>                                if(categoryComponent!=null)
>                                {
>                                        SurveyQuestionResponse response =
> null;
>                                        if(answer!=null)
>                                        {
>                                                response =
> surveyAnswerFactory.getResponse(question, answer);
>
>  if(response.getIdSurveyQuestionResponse()==null)
>                                                {
>                                                        log.info("Creating
> a new answer for this question");
>
>
>  surveyQuestionResponseDAO.save(response);
>
>                                                }
>                                        }
>
>                                        // Each question component holds
> question and answer
>                                        try {
>
> categoryComponent.add(QuestionComponentFactory.getComponent(question,
> response));
>                                        } catch (ComponentTypeException e) {
>                                                try {
>                                                        warn("Response for
> question: " +
> question.getSurveyQuestionDescription() + " has incorrect response!");
>
> categoryComponent.add(QuestionComponentFactory.getComponent(question));
>                                                } catch
> (ComponentTypeException e1) {
>                                                        log.error("Cannot
> create component");
>                                                }
>                                        }
>                                }
>
>
>                        }
>
>                }
>        }
>
>
> >
>



--
Pedro Henrique Oliveira dos Santos

Re: Dynamic Rendering and Common Paramenters

by Gonzalo Aguilar Delgado-4 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

But Pedro,

Everything works well. The form got created and everything gets sent and
updated when I click the submit button.

So in this aspect everything works well.

The only problem is that I need to get a render parameter that actually
I only get in constructor so never gets updated
and I want to know what's the correct way to do this.

I don't think I'm updating a object instance that isn't the one from my
model. I took this into account.

Tnx


El mar, 03-11-2009 a las 14:15 -0200, Pedro Santos escribió:

> Hi Gonzalo, I thought that with buildForm implementation I will see how you
> create your form component. But seams that it is created on the line:
> QuestionComponentFactory.getComponent(question,response)
>
> Instead of ask you for more code, I will try to explain myself:
>
> >So no matter what's the value it will get not updated to the new one.
> Any build component logic will stop you from create an form with an dynamic
> model on it. I thing you are updating an object instance that isn't the one
> on your form model.
> on lines:
>                         response = surveyAnswerFactory.getResponse(question,
> answer);
> and then:
>
>
> categoryComponent.add(QuestionComponentFactory.getComponent(question,
>                                 response));
> be sure of to work on the same response instance that is on your form model.
>
> On Tue, Nov 3, 2009 at 1:38 PM, Gonzalo Aguilar Delgado <
> gaguilar@...> wrote:
>
> >
> >
> >
> > > >I should build the form inside a component instead the page. And I
> > > >should keep a reference
> > > >to the dynamic model inside this component.
> > > Not what I try to mean.
> >
> >
> > So what's the way?
> >
> >
> >
> > >
> > > your report:
> > > >But as I have to build the form I do not have a dynamic model on page.
> > > You can have your model, and you can have your component build logic.
> >
> >
> > mmmm
> >
> >
> > >
> > > you report:
> > >
> > > >So no matter what's the value it will get not updated to
> > > >the new one.
> > > so i think you are working on diferent answer instances
> > > can you send some buildForm(answer) lines?
> >
> >
> > Yes but's somewhat large, anyway answer has got from the code I sent
> > earlier. But it got not
> > updated because this code goes in the constructor that never gets
> > called.
> >
> > Here goes the code:
> >
> >
> >        public void buildForm(SurveyAnswer answer)
> >        {
> >
> >                List<SurveyQuestion> listQuestions = getQuestionList(1); //
> > FIXIT: How
> > do we get this questionaire?
> >
> >                if(listQuestions!=null && listQuestions.size()>0)
> >                {
> >
> >                        int category = -1;
> >                        QuestionCategoryComponent categoryComponent = null;
> >
> >                        /*
> >                         * We add category containers to the component array
> > and
> >                         * questions to the category containers.
> >                         *
> >                         */
> >                        for(Iterator<SurveyQuestion> iter =
> > listQuestions.iterator();
> > iter.hasNext();)
> >                        {
> >                                SurveyQuestion question = iter.next();
> >
> >                                // Check if we should start a new category
> >                                if(category !=
> > question.getSurveyQuestionCategory().getIdSurveyQuestionCategory())
> >                                {
> >                                        log.debug("Category: " +
> > question.getSurveyQuestionCategory().getQuestionCategoryDescription());
> >                                        categoryComponent = new
> > QuestionCategoryComponent("surveyComponent",
> > question.getSurveyQuestionCategory().getQuestionCategoryDescription());
> >                                        components.add(categoryComponent);
> >                                        category =
> > question.getSurveyQuestionCategory().getIdSurveyQuestionCategory();
> >                                }
> >
> >                                if(categoryComponent!=null)
> >                                {
> >                                        SurveyQuestionResponse response =
> > null;
> >                                        if(answer!=null)
> >                                        {
> >                                                response =
> > surveyAnswerFactory.getResponse(question, answer);
> >
> >  if(response.getIdSurveyQuestionResponse()==null)
> >                                                {
> >                                                        log.info("Creating
> > a new answer for this question");
> >
> >
> >  surveyQuestionResponseDAO.save(response);
> >
> >                                                }
> >                                        }
> >
> >                                        // Each question component holds
> > question and answer
> >                                        try {
> >
> > categoryComponent.add(QuestionComponentFactory.getComponent(question,
> > response));
> >                                        } catch (ComponentTypeException e) {
> >                                                try {
> >                                                        warn("Response for
> > question: " +
> > question.getSurveyQuestionDescription() + " has incorrect response!");
> >
> > categoryComponent.add(QuestionComponentFactory.getComponent(question));
> >                                                } catch
> > (ComponentTypeException e1) {
> >                                                        log.error("Cannot
> > create component");
> >                                                }
> >                                        }
> >                                }
> >
> >
> >                        }
> >
> >                }
> >        }
> >
> >
> > >
> >
>
>
>

Re: Dynamic Rendering and Common Paramenters

by Pedro H. O. dos Santos :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

ok, how this parameter get updated? You receive it on every request? If so,
the usual way of to build your render logic dynamically is to implement
component onBeforeRender method, rather than on your component constructor.
See the ListView code for example: based on the model object (an list) the
list items are dynamically add to component. And that render logic is tested
based on list every component render. Similarly, you can have your render
logic executed based on a parameter every component render...

On Tue, Nov 3, 2009 at 3:25 PM, Gonzalo Aguilar Delgado <
gaguilar@...> wrote:

> But Pedro,
>
> Everything works well. The form got created and everything gets sent and
> updated when I click the submit button.
>
> So in this aspect everything works well.
>
> The only problem is that I need to get a render parameter that actually
> I only get in constructor so never gets updated
> and I want to know what's the correct way to do this.
>
> I don't think I'm updating a object instance that isn't the one from my
> model. I took this into account.
>
> Tnx
>
>
> El mar, 03-11-2009 a las 14:15 -0200, Pedro Santos escribió:
>
> > Hi Gonzalo, I thought that with buildForm implementation I will see how
> you
> > create your form component. But seams that it is created on the line:
> > QuestionComponentFactory.getComponent(question,response)
> >
> > Instead of ask you for more code, I will try to explain myself:
> >
> > >So no matter what's the value it will get not updated to the new one.
> > Any build component logic will stop you from create an form with an
> dynamic
> > model on it. I thing you are updating an object instance that isn't the
> one
> > on your form model.
> > on lines:
> >                         response =
> surveyAnswerFactory.getResponse(question,
> > answer);
> > and then:
> >
> >
> > categoryComponent.add(QuestionComponentFactory.getComponent(question,
> >                                 response));
> > be sure of to work on the same response instance that is on your form
> model.
> >
> > On Tue, Nov 3, 2009 at 1:38 PM, Gonzalo Aguilar Delgado <
> > gaguilar@...> wrote:
> >
> > >
> > >
> > >
> > > > >I should build the form inside a component instead the page. And I
> > > > >should keep a reference
> > > > >to the dynamic model inside this component.
> > > > Not what I try to mean.
> > >
> > >
> > > So what's the way?
> > >
> > >
> > >
> > > >
> > > > your report:
> > > > >But as I have to build the form I do not have a dynamic model on
> page.
> > > > You can have your model, and you can have your component build logic.
> > >
> > >
> > > mmmm
> > >
> > >
> > > >
> > > > you report:
> > > >
> > > > >So no matter what's the value it will get not updated to
> > > > >the new one.
> > > > so i think you are working on diferent answer instances
> > > > can you send some buildForm(answer) lines?
> > >
> > >
> > > Yes but's somewhat large, anyway answer has got from the code I sent
> > > earlier. But it got not
> > > updated because this code goes in the constructor that never gets
> > > called.
> > >
> > > Here goes the code:
> > >
> > >
> > >        public void buildForm(SurveyAnswer answer)
> > >        {
> > >
> > >                List<SurveyQuestion> listQuestions = getQuestionList(1);
> //
> > > FIXIT: How
> > > do we get this questionaire?
> > >
> > >                if(listQuestions!=null && listQuestions.size()>0)
> > >                {
> > >
> > >                        int category = -1;
> > >                        QuestionCategoryComponent categoryComponent =
> null;
> > >
> > >                        /*
> > >                         * We add category containers to the component
> array
> > > and
> > >                         * questions to the category containers.
> > >                         *
> > >                         */
> > >                        for(Iterator<SurveyQuestion> iter =
> > > listQuestions.iterator();
> > > iter.hasNext();)
> > >                        {
> > >                                SurveyQuestion question = iter.next();
> > >
> > >                                // Check if we should start a new
> category
> > >                                if(category !=
> > > question.getSurveyQuestionCategory().getIdSurveyQuestionCategory())
> > >                                {
> > >                                        log.debug("Category: " +
> > > question.getSurveyQuestionCategory().getQuestionCategoryDescription());
> > >                                        categoryComponent = new
> > > QuestionCategoryComponent("surveyComponent",
> > > question.getSurveyQuestionCategory().getQuestionCategoryDescription());
> > >
>  components.add(categoryComponent);
> > >                                        category =
> > > question.getSurveyQuestionCategory().getIdSurveyQuestionCategory();
> > >                                }
> > >
> > >                                if(categoryComponent!=null)
> > >                                {
> > >                                        SurveyQuestionResponse response
> =
> > > null;
> > >                                        if(answer!=null)
> > >                                        {
> > >                                                response =
> > > surveyAnswerFactory.getResponse(question, answer);
> > >
> > >  if(response.getIdSurveyQuestionResponse()==null)
> > >                                                {
> > >                                                        log.info
> ("Creating
> > > a new answer for this question");
> > >
> > >
> > >  surveyQuestionResponseDAO.save(response);
> > >
> > >                                                }
> > >                                        }
> > >
> > >                                        // Each question component holds
> > > question and answer
> > >                                        try {
> > >
> > > categoryComponent.add(QuestionComponentFactory.getComponent(question,
> > > response));
> > >                                        } catch (ComponentTypeException
> e) {
> > >                                                try {
> > >                                                        warn("Response
> for
> > > question: " +
> > > question.getSurveyQuestionDescription() + " has incorrect response!");
> > >
> > > categoryComponent.add(QuestionComponentFactory.getComponent(question));
> > >                                                } catch
> > > (ComponentTypeException e1) {
> > >
>  log.error("Cannot
> > > create component");
> > >                                                }
> > >                                        }
> > >                                }
> > >
> > >
> > >                        }
> > >
> > >                }
> > >        }
> > >
> > >
> > > >
> > >
> >
> >
> >
>



--
Pedro Henrique Oliveira dos Santos