Pedro,
Improved version now works. Here is my onclick for the AjaxFallBackLink.
Much of it I think is not best practice. Any tips on making this code
better?
Thanks a million for your help!
P
AjaxFallbackLink up = new AjaxFallbackLink("up") {
@Override
public void onClick(AjaxRequestTarget target) {
AbstractDataSet dataset = datasetmodel.getEntity();
MarkupContainer container=null;
container=getParent();
while(!container.getId().equals("rows")){
container=container.getParent();
}
ListView view=null;
if (container instanceof ListView){
view=(ListView)container;
}
dataset.moveQuestionUp(question); //update the domain model
List list=QuestionProcessor.getMatrixToList(view.getList());
//extract the listview model data
QuestionProcessor.moveQuestionUp(list, question);
view.setList(QuestionProcessor.getListToMatrix(list,
Boolean.TRUE)); //reset the listview model data
adsf.store(dataset); //store my domain data to persist
target.addComponent(outercontainer); //repaint the whole lot
}
};
On Tue, Nov 17, 2009 at 1:47 PM, Pedro Santos <[email protected]> wrote:
> Hi Pieter,
> When you call template.moveQuestionUp(question) you are altering the order
> of the template entity questions list. I think this isn't the same list on
> the row listview model, although both have the same objects.
> All lists used by repeaters are created by QuestionProcessor, you can make
> sure of using those lists operation over rowlistview.getlist() on
> moveQuestionUp implementation.
>
> On Sun, Nov 15, 2009 at 6:56 AM, pieter claassen <
[email protected]>
> wrote:
>>
>> Hi Pedro,
>>
>>
>> Here it is.
>>
>> So, I basically move the question up or down the array.
>>
>> public void moveQuestionUp(QuestionBase question) {
>> int idx = questions.indexOf(question);
>> if (idx > 0) {
>> questions.remove(question);
>> questions.add(idx - 1, question);
>> }
>> }
>>
>> I think that the listview is being redrawn in HTML but the matrix of
>> data underlying it (that I retrieve here in the main page)
>>
>> List<List<QuestionBase>> rows =
>>
>>
QuestionProcessor.getQuestionMatrix(templateWebModel.getEntity().getQuestions(),true);
>>
>> does not get refreshed. I think I need to find a way to reload the
>> data for the listview, from within my panel on a page.
>>
>> Cheers,
>> Pieter
>>
>>
>>
>>
>> On Sun, Nov 15, 2009 at 12:14 AM, Pedro Santos <[email protected]>
>> wrote:
>> > Can you send the moveQuestionUp implementation?
>> >
>> > On Sat, Nov 14, 2009 at 9:03 PM, pieter claassen
>> > <[email protected]>
>> > wrote:
>> >>
>> >> I am trying to follow wicket in action advice P263 but
>> >>
>> >> I have a ListView in a ListView with a panel added to my inner
>> >> listview. On that panel, I have an AjaxLink and I want to move items
>> >> in the order of the listview around. But to display them, I need to
>> >> refresh my "matrix". Nothing seems to work. Any tips or references.
>> >>
>> >> QuestionEditPanel.html
>> >> =================
>> >> <wicket:extend>
>> >> <div id="document">
>> >> <span wicket:id="parent">
>> >> <div wicket:id="rows">
>> >> <span wicket:id="row">
>> >> <span wicket:id="question" />
>> >> </span>
>> >> </div>
>> >> </span>
>> >> </div>
>> >> </wicket:extend>
>> >>
>> >> QuestionEditPanel.java
>> >> ==================
>> >>
>> >> final WebMarkupContainer parent=new
>> >> WebMarkupContainer("parent");
>> >> add(parent);
>> >> parent.setOutputMarkupId(true);
>> >> List<List<QuestionBase>> rows =
>> >>
>> >>
>> >>
QuestionProcessor.getQuestionMatrix(templateWebModel.getEntity().getQuestions(),true);
>> >> ListView rowslistview = new ListView("rows", rows) {
>> >>
>> >> @Override
>> >> protected void populateItem(ListItem item) {
>> >> List<QuestionBase> row = (List<QuestionBase>)
>> >> item.getModelObject();
>> >> ListView rowlistview = new ListView("row", row) {
>> >>
>> >> @Override
>> >> protected void populateItem(ListItem item) {
>> >> final QuestionBase question = (QuestionBase)
>> >> item.getModelObject();
>> >> item.setModel(new
>> >> CompoundPropertyModel(question));
>> >> EditableQuestionPanel questionpanel=new
>> >> EditableQuestionPanel("question", new
>> >> QuestionBaseWebModel(question),templateWebModel,parent);
>> >> item.add(questionpanel);
>> >> ....
>> >>
>> >>
>> >> and then on my EditableQuestionPanel.java I have :
>> >>
>> >> AjaxLink up = new AjaxLink("up") {
>> >>
>> >> @Override
>> >> public void onClick(AjaxRequestTarget target) {
>> >> target.addComponent(parent);
>> >> Template template = templatemodel.getEntity();
>> >> template.moveQuestionUp(question);
>> >> tf.store(template);
>> >> }
>> >> };
>> >> --
>> >> Pieter Claassen
>> >> musmato.com
>> >>
>> >> ---------------------------------------------------------------------
>> >> To unsubscribe, e-mail: [email protected]
>> >> For additional commands, e-mail: [email protected]
>> >>
>> >
>> >
>> >
>> > --
>> > Pedro Henrique Oliveira dos Santos
>> >
>>
>>
>>
>> --
>> Pieter Claassen
>> musmato.com
>
>
>
> --
> Pedro Henrique Oliveira dos Santos
>
--
Pieter Claassen
musmato.com