Problems with composite component
See original GitHub issueI’m testing vue-gwt with very simple test case. And there are some strange things I cannot figure out.
@Component
public class BoilingVerdict extends VueComponent {
@Prop @JsProperty String celsius;
@JsMethod double parseFloat(String value) {
if (value == null) return 0;
String s = value.trim();
if (s.isEmpty()) return 0;
try {
return Double.parseDouble(s);
} catch (Exception e) {
return 0;
}
}
}
BoilingVerdict.html
<p v-if="parseFloat(celsius) >= 100">The water would boil.</p>
<p v-else>The water would not boil.</p>
@Component
public class TemperatureInput extends VueComponent {
@Prop @JsProperty String value;
@Prop @JsProperty String scale;
private static final Map<String, String> scaleNames = new HashMap<String, String>() {{
put("c", "Celsius");
put("f", "Fahrenheit");
}};
@Computed public void setVal(String val) {
this.$emit("input", val);
}
@Computed public String getVal() {
return value;
}
@Computed public String getScaleName() {
return scaleNames.get(scale);
}
}
TemperatureInput.html
<fieldset>
<legend>Enter temperature in {{scaleName}}:</legend>
<input v-model="val" />
</fieldset>
@Component(components = { BoilingVerdict.class, TemperatureInput.class })
public class TemperatureCalc extends VueComponent {
@JsProperty String temperature = "";
@JsProperty String scale = "c";
private static final Function<Double, Double> toCelsius = fahrenheit -> (fahrenheit - 32) * 5 / 9;
private static final Function<Double, Double> toFahrenheit = celsius -> (celsius * 9 / 5) + 32;
private static String tryConvert(String temperature, Function<Double, Double> convert) {
if (temperature == null || temperature.isEmpty()) return "";
try {
double input = Double.parseDouble(temperature);
double output = convert.apply(input);
double rounded = Math.round(output * 1000) / 1000;
return String.valueOf(rounded);
} catch (Exception e) {
return "";
}
}
@Computed public String getCelsius() {
return "f".equals(scale) ? tryConvert(temperature, toCelsius) : temperature;
}
@Computed public void setCelsius(String value) {
scale = "c";
temperature = value;
}
@Computed public String getFahrenheit() {
return "c".equals(scale) ? tryConvert(temperature, toFahrenheit) : temperature;
}
@Computed public void setFahrenheit(String value) {
scale = "f";
temperature = value;
}
}
TemperatureCalc.html
<div>
<div>
<TemperatureInput scale="c" v-model="celsius" />
</div>
<div>
<TemperatureInput scale="f" v-model="fahrenheit" />
</div>
<div>
<BoilingVerdict :celsius="celsius" />
</div>
</div>
First question: Why I have to put every child component to separate div?
In app class I have the following code:
Vue.component("TemperatureInput", TemperatureInput.class);
Vue.component("BoilingVerdict", BoilingVerdict.class);
Vue.component("TemperatureCalc", TemperatureCalc.class);
Vue.attach("#temperatureCalcContainer", TemperatureCalc.class);
Second question: Why I have to register all components manually?
Issue Analytics
- State:
- Created 6 years ago
- Comments:7 (4 by maintainers)
Top Results From Across the Web
Composite component pitfalls: Root component | JSFlive
In my second post in the JSF composite component pitfalls series I would like to discuss the root component of composite components.
Read more >composite component not working - JSF - CodeRanch
My issue is that when I run the application I get the following error: Warning: This page calls for XML namespace http://java.sun.com/jsf/composite/components ......
Read more >jsf - Problems with actionListener of composite component
I am goin to explain a problem that I have when I use one composite component inside a template. Imagine one view like...
Read more >Problems with c:if and composite components #3512 - GitHub
When our servers were updated from JSF Mojarra 2.1.19 to 2.1.28, we started noticing crashes in many pages of our web application.
Read more >Problems with composite IDs processing - PrimeFaces forum
There are three very simple composite components (I omit some boilerplate code) : * Root composite component, which is used at the jsf...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@adrienbaron Thanks! Will try it in the morning.
Great! Thanks for the details 😊! Closing the issue 😉