On 6/28/07, Holda, Dariusz <[EMAIL PROTECTED]> wrote:
Hi Igor,
Thank you for a quick response.
I get your point. My main page should have client object and model that is
referring this object and I should use the same model in DropDownChoice,
Form and Panels for TabbedPanel.
The problem is I have too many clients in my DB to pull them out at the
start up of the page. Other thing is that client object is quite big. That's
why in my DropDownChoice I have only list of clients' names and I'm pulling
out the client from a DB when the specific client is selected.
I haven't specified that in my previous email, but client has list of
objects (accounts, contacts) that are used to populate DropDownChoices in
other tabs. So I have first tab: Profile with general info, and two other
tabs Contacts, Accounts with DropDownChoices from which you can choose which
contact/account to display on the tab form.
Best regards,
Dariusz Holda
A big plus of wicket is that it does let you work with pojos. your page
model should be detachable, so only id is kept permanently and object is
retrieved from the database once per request. also the model that supplies
the list to the dropdownchoice should be a loadabledetachablemodel so that
the list of all clients is only retrieved when needed and not kept around.
makes sense? there is a good page on the wiki about models. your selected
client model can look like something below
class clientmodel implements imodel {
private long id; private transient instance;
object getobject() { if (instance==null&&id!=0) instance=db.clientforid(id);
return isntance; }
void setobject(object client) { instance=client; id=instance.getid(); }
void detach() { instance=null; }
-igor
------------------------------
*From:* [EMAIL PROTECTED] [mailto:
[EMAIL PROTECTED] *On Behalf Of *Igor Vaynberg
*Sent:* 27 June 2007 20:14
*To:* wicket-user@lists.sourceforge.net
*Subject:* Re: [Wicket-user] Problems with updating TabbedPanel
you are not using the models properly
instead of pushing selected objects into models for a lot of components
simply write those components to pull the value from a single place
the workflow is then:
dropdownchoice pushes selected client into a page property
form pulls selected client from that propery
profilepael inside tabbedpanel pulls that client from that property
class mypage extends webpage {
private Client client;
mypage() {
final IModel clientModel=new PropertyModel(this, "client");
setmodel(model);
form f=new form("form");
f.add(new DropDownChoice("client", clientModel, ....) { onchange()
{//noop - model will do all the work} }
profiletab=new abstracttab(..) { getpanel() { return new
profilepanel("id", clientmodel); }
}
that represents all the linkages you need.
-igor
On 6/27/07, Holda, Dariusz <[EMAIL PROTECTED] > wrote:
>
>
> Hi,
> I created TabbedPanel inside a form. The form has just one field which
> is the name of the client. The TabbedPanel stores different information
> about the client. At the top of the page I have DropDownChoice with the
> list of clients. When the client is choose from the DropDownChoice I'm
> changing the model object of the form and model object of the
> tabbedpanel in the onSelectionChanged method. I can see the change in
> the field on the form but to see the changes in the TabbedPanel I have
> to click on a tab. The thing is I want to see the TabbedPanel with the
> new info straight away after choosing the client. Can someone advice me
> something.
> Here are the code snippets:
>
> public class HomePage extends QuickStartPage{
>
> private static final long serialVersionUID = 1L;
>
> SortedSet<String> clientsSet;
> ClientForm clientForm;
> ClientsDropDownChoice clients;
>
> /**
> * Constructor
> */
> @SuppressWarnings("unchecked")
> public HomePage()
> {
> // String permit =
> this.getWebRequestCycle().getWebRequest().getParameter("profileID");
> setModel(new Model("tabpanel"));
> try {
> clientsSet =
> dataPersistenceService.findAllNames();
> List<String> clientsList = new
> LinkedList<String>(clientsSet);
> clients = new
> ClientsDropDownChoice("clients",clientsList);
> add(clients);
> Client client = new Client();
> clientForm = new
> ClientForm("clientForm",client);
> add(clientForm);
> } catch (Exception e) {
> error("Unable to find clients:
> "+e.getMessage());
> e.printStackTrace ();
> }
> }
>
> public void setDataPersistenceService(
> DataPersistenceService dataPersistenceService) {
> this.dataPersistenceService = dataPersistenceService;
> }
>
> void saveClient(Client client) throws DataPersistenceException{
> if(clients.contains(client)){
> client =
> dataPersistenceService.updateClient (client);
> clients.remove(client);
> clients.add(client);
> clientForm.setModelObject(client);
> }else{
>
> client.setId(DataObject.DEFAULT_ID_VALUE);
>
> dataPersistenceService.insertClient(client);
> clients.add(client);
> }
> }
>
> private final class ClientForm extends Form{
>
> private static final long serialVersionUID = 1L;
> TabbedPanel panel;
> Client profile ;
> TabbedPanel tabbedPanel;
>
> @SuppressWarnings("synthetic-access")
> public ClientForm(String name, Client client) {
> super(name, new CompoundPropertyModel(client));
> final FeedbackPanel feedback = new
> FeedbackPanel("feedback");
> add(feedback);
> add(new TextField("clientName").add(new
> AjaxFormComponentUpdatingBehavior("onchange")));
>
> // add the new tabbed panel, attribute modifier
> only used to switch
> // between different css variations
> profile = client;
> tabbedPanel =
> createTabsPanel((Client)this.getModelObject());
> add(tabbedPanel);
> }
>
> public void updateTabs(Client client){
> profile = client;
> }
>
> public TabbedPanel createTabsPanel(final Client client){
>
> List<AbstractTab> tabs = new
> ArrayList<AbstractTab>();
> tabs.add(new AbstractTab(new Model("Profile"))
> {
> private static final long
> serialVersionUID = 1L;
> @SuppressWarnings("synthetic-access")
> @Override
> public Panel getPanel(String panelId)
> {
> ProfilePanel panel = new
> ProfilePanel(panelId, profile);
>
> panel.setDataPersistenceService(dataPersistenceService);
> return panel;
> }
>
> });
>
> panel = new TabbedPanel("tabs", tabs);
>
> panel.add(new AttributeModifier("class",
> true,HomePage.this.getModel()));
> return panel;
> }
>
> }
>
> private final class ClientsDropDownChoice extends
> DropDownChoice{
>
> private static final long serialVersionUID = 1L;
>
> @SuppressWarnings("synthetic-access")
> public ClientsDropDownChoice(String arg0, List<String>
> choices) {
> super(arg0, new Model(), choices, new
> ChoiceRenderer());
> }
>
> /**
> * @see
> wicket.markup.html.form.DropDownChoice#wantOnSelectionChangedNotificatio
> ns()
> */
> @Override
> public boolean wantOnSelectionChangedNotifications()
> {
> // we want roundtrips when a the user selects
> another item
> return true;
> }
>
>
> @SuppressWarnings("synthetic-access")
> @Override
> public void onSelectionChanged(Object newSelection){
> Client clientOld =
> (Client)clientForm.getModelObject();
> if(clientOld.getClientName()!=null){
> try{
> saveClient(clientOld);
> } catch (Exception e) {
> e.printStackTrace();
> error("Attempt to save
> the client "+clientOld.getClientName()+
> " failed
> because: "+e.getMessage());
> return;
> }
> }
> String name = (String)newSelection;
> Client client = null;
> try{
> client =
> dataPersistenceService.findByName(name);
> } catch (Exception e){
> e.printStackTrace();
> error("Unable to find a client
> with a name:"+name+"\n"+e.getMessage());
> return;
> }
> clientForm.updateTabs(client);
>
> clientForm.setModelObject(client);
> }
>
> public boolean contains(Client dObject){
> return
> this.getChoices().contains(dObject.getClientName ());
> }
>
> @SuppressWarnings("unchecked")
> public void add(Client dObject){
> getChoices().add(dObject.getClientName());
> }
>
> public void remove(Client dObject){
> getChoices().remove(dObject.getClientName());
> }
>
> }
> }
> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
> - - - - - - - -
>
> This message is intended only for the personal and confidential use of
> the designated recipient(s) named above. If you are not the intended
> recipient of this message you are hereby notified that any review,
> dissemination, distribution or copying of this message is strictly
> prohibited. This communication is for information purposes only and should
> not be regarded as an offer to sell or as a solicitation of an offer to buy
> any financial product, an official confirmation of any transaction, or as an
> official statement of Lehman Brothers. Email transmission cannot be
> guaranteed to be secure or error-free. Therefore, we do not represent that
> this information is complete or accurate and it should not be relied upon as
> such. All information is subject to change without notice.
>
>
>
>
>
> -------------------------------------------------------------------------
> This SF.net email is sponsored by DB2 Express
> Download DB2 Express C - the FREE version of DB2 express and take
> control of your XML. No limits. Just data. Click to get it now.
> http://sourceforge.net/powerbar/db2/
> _______________________________________________
> Wicket-user mailing list
> Wicket-user@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/wicket-user
>
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - This message is intended only for the personal and
confidential use of the designated recipient(s) named above. If you are not
the intended recipient of this message you are hereby notified that any
review, dissemination, distribution or copying of this message is strictly
prohibited. This communication is for information purposes only and should
not be regarded as an offer to sell or as a solicitation of an offer to buy
any financial product, an official confirmation of any transaction, or as an
official statement of Lehman Brothers. Email transmission cannot be
guaranteed to be secure or error-free. Therefore, we do not represent that
this information is complete or accurate and it should not be relied upon as
such. All information is subject to change without notice.
-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Wicket-user mailing list
Wicket-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/wicket-user
-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Wicket-user mailing list
Wicket-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/wicket-user