I am trying to learn Wicket. One of the problems I encounter, is changing the values of components like a label.
This is how I declare the label:
Label message = new Label("message", new Model<String>(""));
message .setOutputMarkupId(true);
add(message );
The only solution I can find:
Label newMessage= new Label(message.getId(), "MESSAGE");
newMessage.setOutputMarkupId(true);
message.replaceWith(newMessage);
target.add(newMessage);
Is there a better/easier way to edit the value of a Wicket label and display this new value to the user?
Thanks!
I think you did not understand what Models are. Your example could be rewritten as follows
Model<String> strMdl = Model.of("My old message");
Label msg = new Label("label", strMdl);
msg.setOutputMarkupId(true);
add(msg);
In your ajax event
strMdl.setObject("My new message");
target.add(msg);
Related
I try to make a label to display "You Win" and add it to winStage, but I cannot manage to display the label correctly on winStage. Some words don't show on the screen, and if I downscale further than 0.044f, the String disappears. when I add font.setUseIntegerPositions(false) to my code, the font shows correct, but the wrong label also shows. Is there a way to get this work? (hide the wrong label or get the label shows correctly), code uses Kotlin, but very similar to java
YUW N is the wrong label I want to remove, the correct "You Win" only shows when I add font.setUseIntegerPositions(false)
here's the relevant code part
private val winViewport = StretchViewport(mainStage.width, mainStage.height)
val winStage = Stage(winViewport, winBatch)
var font = BitmapFont()
var labelStyle = Label.LabelStyle()
labelStyle.font = font
labelStyle.fontColor = Color.RED
var label2 = Label("YOU WIN", labelStyle)
label2.setBounds(0f, winStage.height*2/3, winStage.width*1, winStage.height/6)
label2.setFontScale(0.07F) // 0.07f
font.setUseIntegerPositions(false)
label2.setWrap(false)
winStage.addActor(label2)
winStage.act(delta)
winStage.draw()
i'm new in java, i try to add new lines in a message string:
String message = "Test User1,\n Test User2,\n Test User1";
WindowMessage win2 = new WindowMessage("The following Names are duplicate : "+messages);
win2.setModal(true);
app.addWindow(win2);
i tried to add \r\n, \n, %r%n, %n, but none of them working
in my WindowMessage(extends WindowPane) class, the Message is set as a Label:
lblMessage.setText(Message);
Any idea why?
Try using JOptionPane.showMessageDialog
It's not clear which API you're using, but try using a JLabel with html:
JLabel l = new JLabel("<html>line1<br>line2</html>");
If you are using a library that does not support multilines within the same label (check the docs!), then you should stack two labels on top of each other:
Label line1 = ...
Label line2 = ...
If you do not have control over how many labels you can add, then what you are trying to do is not possible with your library.
I've created a jasper report with iReport and I can print it perfectly.
I need to print 3 examples of it (original example, client example, department example) with very few changes, for example changing a label in the report.
I pass PRINT_FOR as parameter to iReport.
Does any body know how to approach this goal?
HashMap parameters = new HashMap();
String option = "C:\\option.jasper";
JRDataSource beanDataSource = reportMapper.getDataSource();
JasperPrint jasperPrint = JasperFillManager.fillReport(option, parameters, beanDataSource);
JasperPrintManager.printPage(jasperPrint, 0, true))
A first thought is just make a general report template and have some "hooks" in which you can insert the differences for each version; you can send the "differences" via the parameters from Java.
Instead of using a Static Text field you can use a Text Field that allows you to use and expression to determine the text output. In this case you would check to see if the PRINT_FOR parameter is equal to the client or department and if not use the original value. You expression would look something like this:
($P{PRINT_FOR}.equals("DEPARTMENT") ? "Department Label" : ($P{PRINT_FOR}.equals("CLIENT") ? "Client Label" : "Original Label"))
Where Department Label is outputted when PRINT_FOR is equal to DEPARMTNENT, Client Label is outputted when PRINT_FOR is equal to Client, and Original Label is outputted if it is not equal to either of the above.
Also worth noting is that in the code snippet about you never set the value for the PRINT_FOR parameter in your java code and you are not using a generic HashMap. It should look something closer to:
Map<String, Object> parameters = new HashMap<String, Object>();
parameters.put("PRINT_FOR", "CLIENT");
UPDATE: Based on your comment, you basically want to do export all 3 reports as one at the same time. This can be accomplised by using the JRPrintServiceExporter. Basically create the three JasperPrint Objects, and put them in a list. Then use the exporter to print them out. Something like:
//add all three JasperPrints to the list below
List<JasperPrint> jasperPrints = new ArrayList<JasperPrint>();
...
//create an exporter
JRExporter exporter = new JRPrintServiceExporter();
//add the JasperPrints to the exporter via the JASPER_PRINT_LIST param
exporter.setParameter(JRExporterParameter.JASPER_PRINT_LIST, jasperPrints);
exporter.setParameter(JRPrintServiceExporterParameter.DISPLAY_PAGE_DIALOG, Boolean.FALSE);
exporter.setParameter(JRPrintServiceExporterParameter.DISPLAY_PRINT_DIALOG, Boolean.TRUE);
//this one makes it so that the settings choosen in the first dialog will be applied to the
//other documents in the list also
exporter.setParameter(JRPrintServiceExporterParameter.DISPLAY_PRINT_DIALOG_ONLY_ONCE, Boolean.TRUE);
exporter.exportReport();
When you use your own JRBeanCollectionDataSource, you must create for each JasperPrint their respective JRBeanCollectionDataSource
JRBeanCollectionDataSource dsCliente = new JRBeanCollectionDataSource(listaDetalle);
JasperPrint jasperPrintCliente = JasperFillManager.fillReport("plantillaDoc.jasper", paramsHojaCliente, dsCliente);
listaJasperPrint.add(jasperPrintCliente);
JRBeanCollectionDataSource dsCaja1 = new JRBeanCollectionDataSource(listaDetalle);
JasperPrint jasperPrintCaja1 = JasperFillManager.fillReport("plantillaDoc.jasper", paramsHojaCaja, dsCaja1);
listaJasperPrint.add(jasperPrintCaja1);
Below code only showing the textfield, but I want to include textfield and textarea. Need Help
form1 = new Form("Mobile");
tb2 = new TextField("To: ", "", 30, TextField.ANY);
TextBox tb3 = new TextBox("Message: ", "", 256, TextField.ANY);
form1.append(tb2);
// form1.append(tb3);
form1.addCommand(submitCommand);
display.setCurrent(tb3);
display.setCurrent(form1);
What you call textarea is an lcdui object TextBox; it can not be shown at the same screen as TextField.
If you're interested, refer to 'lcdui' tag info for more details on why is that (there are links to API reference, tutorials, popular libraries etc).
For the code snippet you posted, first thing that comes to mind would be to just replace TextBox to TextField, like
// ...initialization of Form and tb2
TextField tb3 = new TextField("Message: ", "", 256, TextField.ANY);
// above, TextBox has been replaced with TextField
form1.append(tb3); // show "Message" textfield above "Mobile"
form1.append(tb2);
form1.addCommand(submitCommand);
display.setCurrent(form1);
There is no such thing as TextArea in J2ME. You can show either Form with TextField[s] or TextBox, because TextBox is a Displayable. You can show only one Displayable at a time.
We have basic ListGrid where one of the fields is editable and editor for this field always should be displayed, here is creation code
ListGrid listPanel = new ListGrid();
listPanel.setDataFetchMode(FetchMode.PAGED);
listPanel.setDataSource(datasource);
listPanel.setAutoFetchData(true);
listPanel.setAlwaysShowEditors(true);
listPanel.setCanEdit(true);
listPanel.setAutoSaveEdits(false);
listPanel.setSaveByCell(false);
listPanel.setEditOnFocus(true);
listPanel.setEditEvent(ListGridEditEvent.CLICK);
editable field is created here
ListGridField manualScoreColumn = new ListGridField("score", "Score");
manualScoreColumn.setType(ListGridFieldType.INTEGER);
manualScoreColumn.setCanEdit(true);
manualScoreColumn.setValidateOnChange(true);
manualScoreColumn.setValidators(new IntegerRangeValidator());
problem is when data in ListGrid is filtred using
listPanel.setCriteria(criteria);
we get such exeption
12:42:31.204:RDQ2:WARN:Log:TypeError: _5 is null
ListGrid._clearingInactiveEditorHTML() # adminApp/sc/modules/ISC_Grids.js:1530
GridBody.redraw(_1=>false) # adminApp/sc/modules/ISC_Grids.js:889
[c]Canvas.clearRedrawQueue() # adminApp/sc/modules/ISC_Core.js:3300
[c]Class.fireCallback(_1=>{Obj}, _2=>undef, _3=>[object Array], _4=>{Obj}, _5=>true)
# adminApp/sc/modules/ISC_Core.js:299
Timer._fireTimeout("$ir2251") # adminApp/sc/modules/ISC_Core.js:1269
unnamed() # adminApp/sc/modules/ISC_Core.js:1264
unnamed() #
I've found similar question here and here but no solution was proposed.
Are there any workarounds ? Thanks.
Make sure you have set ListGridField to ListGrid
listPanel.setFields(manualScoreColumn);
Another way to set editor of your choice to ListGridField is to use setEditorType method
ListGrid listPanel = new ListGrid();
listPanel.setCanEdit(true);
listPanel.setAutoSaveEdits(false);
//You can use any formitem instead of date item,Say TextItem,SelectItem etc
DateItem dateItem = new DateItem();
ListGridField dateListGridField= new ListGridField("date", "Date");
dateListGridField.setEditorType(dateItem);
listPanel.setFields(dateListGridField);